﻿ package {
      import flash.display.Sprite;
      import flash.text.TextField;
      import flash.text.TextFormat;
      import flash.text.TextFieldAutoSize;
      import flash.events.*;
 
      public class ButtonInteractivity extends Sprite {
 	      public var levelValue:String = "";
          private var button:Sprite = new Sprite();
 
          public function ButtonInteractivity(x:Number, y:Number, text:String) {
              drawButton(x, y, text);
			  levelValue = text.toLowerCase();
              button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
              addChild(button);
          }
 
          private function drawButton(x:Number, y:Number, text:String):void {
              var textFormat:TextFormat = new TextFormat();
			  textFormat.font = "Franklin Gothic Book";
			  textFormat.size = 14;
			  var textLabel:TextField = new TextField()
              textLabel.text = text;
			  textLabel.autoSize = TextFieldAutoSize.CENTER;
			  textLabel.multiline = false;
			  textLabel.setTextFormat(textFormat);
			  //textLabel.embedFonts = true;
			  button.graphics.clear();
              button.graphics.beginFill(0x00FF00); // grey color
              button.graphics.drawRoundRect(x, y, textLabel.width + 15, textLabel.height + 10, 10, 10); // x, y, width, height, ellipseW, ellipseH
              button.graphics.endFill();
              textLabel.x = x + 7.5;
              textLabel.y = y + 5;
              textLabel.selectable = false;
              button.addChild(textLabel)
          }
 
          private function mouseDownHandler(event:MouseEvent):void {
              dispatchEvent(new Event("LevelSelectedEvent"));
          }
      }
  }